const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    firstAvatar: '',
    secondAvatar: '',
    score: 0,
    relation: ''
  },

  // 关系判断
  getRelationInfo(score) {
    let relation = '';
    switch (true) {
      case score < 20:
        relation = '路人';
        break;
      case 20 <= score && score < 50:
        relation = '同事';
        break;
      case 50 <= score && score < 60:
        relation = '朋友';
        break;
      case 60 <= score && score < 80:
        relation = '家人';
        break;
      case 80 < score && score <= 100:
        relation = '恋人';
        break;
    }
    return relation;
  },

  bgStyle(key) {
    let url = key;
    return `background: url(${url}) no-repeat;
            background-size: contain;
            background-position: center;`;
  },

  toResultPage(){
    wx.navigateTo({
      url: '../result/result'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { firstAvatarUrl, secondAvatarUrl, score } = app.globalData;

    this.setData({
      score: parseInt(score),
      firstAvatar: this.bgStyle(firstAvatarUrl),
      secondAvatar: this.bgStyle(secondAvatarUrl),
      relation: this.getRelationInfo(score)
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})